<script>
	$(document).ready(function(){
	
	jQuery.validator.addMethod("not_white", function(value, element) 
	{ 
		return( !hasWhiteSpace(value));
	}, jQuery.format("<?php echo __('field_name not blank'); ?>"));
	
		
		$("#KtconfigurationAddForm").validate();

		$("#btn_save").click(function(){
			if($("#KtconfigurationName").attr("value").search(" ")>-1) 
			{
				$("#dflt_dialog").text("<? echo __('El nombre no puede contener espacios en blanco.'); ?>").dialog("open"); 
				return 0;
			}	
			
			work_folder_exist();
		
		})		


	
		function work_folder_exist()
		{
			var parametros ="&dir="+($("#KtconfigurationDirectory").attr("value"));
			$.ajax
			({
				type: "post",
				url:"<?php echo $this->base ?>/ktconfigurations/work_folder_exist",
					data:parametros,
					beforeSend: function()
					{
						
					},			
					success: function(datos)
					{
						if(datos=="true")
						{
							$("#dflt_dialog").dialog('option', 'buttons', { "Sobrescribir": function() { $(this).dialog("close"); $("#KtconfigurationAddForm").submit(); },"Cancelar": function() { $(this).dialog("close"); } });
							$("#dflt_dialog").text("<? echo __('El nombre del directorio ya existe. Desea Sobreescribirlo?. Esta operacion no se puede deshacer.'); ?>").dialog("open");
						}
						else
							$("#KtconfigurationAddForm").submit();
					}
				})	
		}
		
	});
	
	function hasWhiteSpace(s) 
	{
	     reWhiteSpace = new RegExp(/\s/);
	     if (reWhiteSpace.test(s)) return true;
			return false;
	}	




</script>

<div class="kt-g1">
		<div class=" kt-right">
	   		<ul class="lst-tabs">
	   		   	   	<li id="icon-new" class="active"> <span class="icon"></span> <?php echo $html->link(__('configurations_new',true),$ruta_admin.'/add');?> </li>	    				
	    			<li id="icon-configuration"> <span class="icon"></span> <?php echo $html->link(__('configurations_list',true),$ruta_admin.'/');?> </li>	    				
	   	</ul>	  
		</div>
</div>
<div class="kt-md kt-md-content">	
		<div class="hd">
			 <h2> <?php __('configuration_title_new') ?></h2>	
		</div>
		<div class="bd">	
		  <?php if (!is_writable(CONFIGS.'database.php')) { ?>					
		  		<div class="kt-md-group clearfix configuration">
				<p class="error_msg"> <?php  __('Your database file is NOT writable.'); ?> 
				  <?php  __('configurations will not safe and will not work correctly'); ?>
				 </p> 
			</div>
			 <?php	}	?>
			<div class="lst-form">	
			<?php 
				echo $form->create('Ktconfiguration');
			?>	
			<table>			
			<tr class="form-field"> 
				 <td>
				 	<p><?php echo $form->input('name',array('label'=>__('name',true),'class'=>'required not_white'));?> </p>
				</td>	
				 <td>
					<p><?php echo $form->input('directory', array('label' => __('directory',true),'class'=>'required') );?> </p>
				</td>
				 	
			</tr>
			<tr class="form-field"> 
				 <td>
					<p><?php echo $form->input('hosts', array('label' => __('hosts',true),'class'=>'required') );?> </p>
				</td>
				 <td>
					 <p><?php echo $form->input('database', array('label' => __('database',true),'class'=>'required') );?> </p>
				 </td>		
			</tr>
			
			<tr class="form-field"> 
				 <td>
					<p><?php echo $form->input('login', array('label' => __('login',true),'class'=>'required'));?> </p>
				</td>
				 <td>
					 <p><?php echo $form->input('password', array('label' => __('password',true)));?> </p>
				 </td>		
			</tr>
			<tr class="form-field"> 
				 <td>
					<p><?php echo $form->input('url', array('label' => __('url',true),'class'=>'required'));?> </p>
				</td>
				  	
			</tr>
			</table>
			
			<p class="submit">
			  	<?php echo $form->button(__('save',true),array("id"=>"btn_save",  'class' => 'boton' )); ?>
			</p>
			
			  <?php echo $form->end();?>  
			</div>
		</div>
		<div class="ft">
		<p>	<?php echo $html->link(__('configurations_create_new',true), $ruta_admin."add/");?> - <?php echo $html->link(__('comeback',true), $ruta_admin); ?></p>
		</div>

</div>

